package recursion.leetcode.editor.cn;

import recursion.leetcode.editor.cn.common.ListNode;

public class UHnkqh {
    public static void main(String[] args) {
        Solution solution = new UHnkqh().new Solution();
        ListNode a = new ListNode(1);
        ListNode a1 = new ListNode(2);
        ListNode a2 = new ListNode(3);
        ListNode a3 = new ListNode(4);
        a.next = a1;
        a1.next = a2;
        a2.next = a3;
        ListNode x = solution.reverseList(a);
        System.out.printf(x.toString());
    }
    //leetcode submit region begin(Prohibit modification and deletion)

    class Solution {
        public ListNode reverseList(ListNode head) {
            if (head == null || head.next == null) {
                return head;
            }
            ListNode nexthead = head.next;
            ListNode listNode = reverseList(nexthead);
            head.next = null;
            nexthead.next = head;
            return listNode;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}